package com.javafamily.familydemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

// 表示当前类为配置类
@Configuration
// 启用SwaggerAPI文档
@EnableSwagger2
public class SwaggerConfig {
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API")
                .description("一起看下API文档吧")
                .termsOfServiceUrl("http://www.JavaFamily.com")
                .version("V1")
                .build();
    }

    @Bean
    public Docket createApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 把根目录下的所有接口函数形成文档
                .apis(RequestHandlerSelectors.basePackage("com.javafamily.familydemo"))
                .paths(PathSelectors.regex("/.*"))
                .build();
    }
}
